import Util from 'assets/js/util'
import PCUtil from '../pc-util'
export default {
  data () {
    return {
      searchCondition: {  //查询条件
        mobile: '',
        keyword: '',
        userType: -1,
        reportStatus: 1,
        followManage: '',
        userFeedback: -1,
        createDate: [],
        dealDate: []
      },
      seekflag: true,
      isNobodyHandled: false,
      isZfxf: false,
      isAsc: true,
      userTypeList:[//用户类型下拉框
        {value:-1,label:'全部'},
        {value:1,label:'实名用户'},
        {value:2,label:'匿名用户'}
      ],
      reportStatusList:[//状态下拉框
        {value:-1,label:'全部'},
        {value:1,label:'处理中'},
        {value:2,label:'已办结'}
      ],
      userFeedbackList:[//用户反馈下拉框
        {value:-1,label:'全部'},
        {value:0,label:'未评价'},
        {value:2,label:'满意'},
        {value:1,label:'不满意'}
      ],
      reportList: false, //举报处理
      pageSize: 10,
      pageNum: 1,
      dataTotal: 1,
      pageCount: 1,
      showWarnModal:false, //格式校验提示框
      warnContent:''  //提示文案
    }
  },
  filters:{
    reportStatusStr:function(val){
      if(val==0){
        return '处理中';
      }else if(val==1){
        return '处理中';
      }else if(val==2){
        return '已办结';
      }
    }
  },
  mounted () {
    this.init();
  },
  beforeRouteEnter (to, from, next) {
    if('reportHandleDetail'!=from.name && 'subjectDetail'!=from.name){
      sessionStorage.removeItem('search_con')
    }
    next();
  },
  methods: {
    init: function () {
      let routeName = this.$route.name
      if (routeName == "reportHandlingList") {
        Util.setTitle('举报处理');
        let oldParams=Util.sessionData('search_con'),param;
        if(oldParams){
          param=oldParams;
          this.searchCondition = {  //查询条件
            mobile: oldParams.mobile,
            keyword: oldParams.keyword,
            userType: oldParams.userType,
            reportStatus: oldParams.reportStatus,
            followManage: oldParams.followManage,
            userFeedback: oldParams.userFeedback,
            createDate: (oldParams.startCreateDate&&oldParams.endCreateDate)?[oldParams.startCreateDate,oldParams.endCreateDate]:[],
            dealDate: (oldParams.startDealDate&&oldParams.endDealDate)?[oldParams.startDealDate,oldParams.endDealDate]:[]
          }
          this.isNobodyHandled= oldParams.isNobodyHandled;
          this.isZfxf= oldParams.isZfxf;
          if(oldParams.isAsc ==1){
            this.isAsc= true;
          }else{
            this.isAsc= false;
          }
          //this.isAsc= oldParams.isAsc;
          this.pageNum=oldParams.pageNum
        }else{
          param = {
            pageNum: 1,
            pageSize: this.pageSize,
            isNobodyHandled: this.isNobodyHandled?1:0,
            isZfxf: this.isZfxf?1:0,
            isAsc: this.isAsc?1:2,
            reportStatus:1,   //处理中
          }
        }
        this.queryReportList(param)
      }
    },
    /**
     * 查看举报处理
     * @param params
     */
    viewReport(convId){
      this.$router.push({
        name: 'reportHandleDetail',
        params: {pageType: 'view'},
        query: {reportId: convId}
      })
    },
    /**
     * 查看举报处理
     * @param params
     */
    handleReport(convId){
      this.$router.push({
        name: 'reportHandleDetail',
        params: {pageType: 'handle'},
        query: {reportId: convId}
      })
    },
    /**
     * 查询
     * @param param
     */
    search(pageNum){
      var _this=this;
      if(!this.seekflag)  return false;
      this.seekflag = false;
      setTimeout(function(){
        _this.seekflag = true;
      },2000);
      this.pageNum = pageNum ? pageNum : 1;
      if (this.searchCondition.mobile) {
        let isValidatePhone = /^1[34578]\d{9}$/.test(this.searchCondition.mobile)
        if (!isValidatePhone) {
          this.$Notice.warning({
            title: '温馨提示',
            desc: '手机号格式不正确',
            duration:2,
          });
          return;
        }
      }
      var param = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        mobile: this.searchCondition.mobile,
        keyword: this.searchCondition.keyword,
        userType: this.searchCondition.userType,
        reportStatus: this.searchCondition.reportStatus,
        followManage: this.searchCondition.followManage,
        userFeedback: this.searchCondition.userFeedback,
        startCreateDate: PCUtil.date2TimeStamp(this.searchCondition.createDate[0]),
        endCreateDate: PCUtil.date2TimeStamp(this.searchCondition.createDate[1]),
        startDealDate: PCUtil.date2TimeStamp(this.searchCondition.dealDate[0]),
        endDealDate: PCUtil.date2TimeStamp(this.searchCondition.dealDate[1]),
        isNobodyHandled: this.isNobodyHandled?1:0,
        isZfxf: this.isZfxf?1:0,
        isAsc: this.isAsc?1:2
      }
      this.queryReportList(param);
    },
    /**
     * 查询举报处理接口
     * @param param
     */
    queryReportList(param){
      let _this = this;
      Util.sessionData('search_con',param);
      param.userType=param.userType==-1? "": param.userType;
      param.reportStatus=param.reportStatus==-1? "": param.reportStatus;
      param.userFeedback=param.userFeedback==-1? "": param.userFeedback;
      this.$http.post('convphotoManage/queryReportList', param)
        .then(function (data) {
          if (data.meta.code == '0') {
            _this.dataTotal = data.data.dataTotal || 0;
            _this.pageCount = data.data.pageCount || 0;
            _this.reportList = data.data.result || [];
          } else {
            // _this.$Modal.warning({
            //   title: '温馨提示',
            //   content: data.meta.message
            // });
            _this.showWarnModal = true;
            _this.warnContent = data.meta.message;
          }
        })
        .catch(function (err) {
          // _this.$Modal.warning({
          //   title: '温馨提示',
          //   content: err.meta.message
          // });
          _this.showWarnModal = true;
          _this.warnContent = err.meta.message;
        })
    },
    /**
     * 清空查询条件
     */
    reset(){
      this.searchCondition = {  //查询条件
        mobile: '',
        keyword: '',
        userType: -1,
        reportStatus: 1, //处理中
        followManage: '',
        userFeedback: -1,
        createDate: [],
        dealDate: []
      }
      this.isNobodyHandled= false;
      this.isZfxf= false;
      //this.isAsc=false;  不清空勾选
      sessionStorage.removeItem('search_con')

    },
    /**
     * 选择创建事件
     * @param data
     */
    selectCreateDate(data){
      if (data.length == 2) {
        this.searchCondition.createDate[0] = data[0] + ' 00:00:00';
        this.searchCondition.createDate[1] = data[1] + ' 23:59:59';
      }
    },
    /**
     * 选择处理时间
     * @param data
     */
    selectDealDate(data){
      if (data.length == 2) {
        this.searchCondition.dealDate[0] = data[0] + ' 00:00:00';
        this.searchCondition.dealDate[1] = data[1] + ' 23:59:59';
      }
    },
    goToSubject: function(item){
      this.$router.push({
        name: "subjectDetail",
        query:{
          subjectId:item.subjectId
        }
      })
    },
    closeModal(){
      this.showWarnModal = false;
    },
    checknumber(){
      this.searchCondition.mobile =this.searchCondition.mobile.replace(/[^0-9]/g,'');
    }
  }
}
